<script>
var yearDatePicker;
var monthDatePicker;
var pdate;
var dateStr;
	$(function() {
		window.prettyPrint && prettyPrint();
		$('#dp1').fdatepicker({});
		$('#dp2').fdatepicker({});
		$('#dp3').fdatepicker({});
		$('#dp4').fdatepicker({});
		$('#dp5').fdatepicker({});
		// implementation of disabled form fields
		var nowTemp = new Date();
		var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp
				.getDate(), 0, 0, 0, 0);
		
		setDateVal(nowTemp);
		$('#dpd1').val(dateStr);
		$('#dpd2').val(dateStr);
				
		var depart = $('#dpd1').fdatepicker({
			onRender : function(date) {
				return date.valueOf() < now.valueOf() ? 'disabled' : '';
			}
		}).on('changeDate', function(ev) {
			if (ev.date.valueOf() >= returndate.date.valueOf()) {
				var newDate = new Date(ev.date)
				setDateVal(newDate);
				returndate.setValue(newDate);
				$('#dpd2').val(dateStr);
			}
			depart.hide();
			$('#dpd2')[0].focus();
		}).data('datepicker');
		
		var returndate = $('#dpd2')
				.fdatepicker(
						{
							onRender : function(date) {
								return date.valueOf() < depart.date.valueOf() ? 'disabled'
										: '';
							}
						}).on('changeDate', function(ev) {
					returndate.hide();
				}).data('datepicker');
		
		// date picker for eidt task
		var departTask = $('#dpd4').fdatepicker({
			onRender : function(date) {
				return date.valueOf() < now.valueOf() ? 'disabled' : '';
			}
		}).on('changeDate', function(ev) {
			if (ev.date.valueOf() >= returndateTask.date.valueOf()) {
				var newDate = new Date(ev.date)
				setDateVal(newDate);
				returndateTask.setValue(newDate);
				$('#dpd5').val(dateStr);
			}
			departTask.hide();
			$('#dpd5')[0].focus();
		}).data('datepicker');
		
		var returndateTask = $('#dpd5')
				.fdatepicker(
						{
							onRender : function(date) {
								return date.valueOf() < departTask.date.valueOf() ? 'disabled'
										: '';
							}
						}).on('changeDate', function(ev) {
							returndateTask.hide();
				}).data('datepicker');
		
		// date picker use for profile
		$('#dpd3').fdatepicker({
			format : 'yyyy-mm-dd',
			onRender : function(date) {
				return date.valueOf() >= now.valueOf() ? 'disabled' : '';
			}
		})
	});
	
	function setDateVal(inputDate){
		yearDatePicker = inputDate.getFullYear();
		monthDatePicker = inputDate.getMonth() + 1;
		if (parseInt(monthDatePicker) < 10) {
			monthDatePicker = "0" + monthDatePicker;
		}
		pdate = inputDate.getDate();
		if (parseInt(pdate) < 10) {
			pdate = "0" + pdate;
		}
		dateStr = yearDatePicker + "/" + monthDatePicker + "/" + pdate;
	}
</script>